﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Net.Mail;
using System.Net;

namespace GreenLife
{
    public partial class LienHe : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            string name = txtUserNameContact.Text;
            string body = txtMessageContent.Text;
            string mail = txtEmailContact.Text;
            Send_Email(mail, name, "", body);
        }
        public void Send_Email(string SendFrom, string name, string Subject, string Body)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);
                sc.Credentials = new NetworkCredential("mr.special8x@gmail.com", "DUNGPHONG");
                mail.From = new MailAddress(SendFrom, name + " gửi tới form liên hệ", System.Text.Encoding.UTF8);
                mail.To.Add("mr.special8x@gmail.com");
                mail.Subject = "Mail từ Form liên hệ của " + SendFrom;
                mail.Body = Body +"\n Thư được gửi từ địa chỉ: "+SendFrom;
                sc.EnableSsl = true;
                sc.Send(mail);
                Response.Write("<script language='javascript'>alert('Cảm ơn đóng góp của bạn!')</script>");
            }
            catch (Exception ex)
            {
                Response.Write("<script language='javascript'>alert('Lỗi!')</script>");
            }
        }
    }
}